using ASP;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Shop_Member_AddMyFav : Member, IRequiresSessionState
{
	protected Image ProductImage1;
	protected HyperLink HL_ProductID;
	protected HyperLink Hl_ProductName;
	protected Label LabProductPrice;
	protected Label LabLeftTime;
	protected HyperLink HL_UserName1;
	protected DropDownList DropF_ProductClassID;
	protected Button Button3;
	protected TextBox TxtF_Remark;
	protected Button ProductButton;
	protected Panel Panel;
	protected Image ShopImage1;
	protected HyperLink HL_ShopName;
	protected HyperLink HL_ShopClassName;
	protected HyperLink HL_UserName2;
	protected HyperLink HL_ShopLel;
	protected DropDownList DropF_ShopClassID;
	protected Button Button4;
	protected TextBox TxtF_Remark1;
	protected Button ShopButtonClick;
	protected Button Button1;
	protected Panel Pane2;
	protected HiddenField H_FavID;
	protected HiddenField H_ProductID;
	protected HiddenField H_ShopID;
	public int F_ID = 0;
	public int F_UserID = 0;
	public int UserID = 0;
	public int ShopID = 0;
	public int ProductID = 0;
	public int ShopCategoryID;
	public string m_flag = "0";
	public string m_installDir = "/";
	public new string m_ShopDir = "/Shop/";
	public string AddMyFav;
	private UserInfoBll _bllUserInfo = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public UserInfoBll BllUserInfo
	{
		get
		{
			if (this._bllUserInfo == null)
			{
				this._bllUserInfo = new UserInfoBll(this.conn);
			}
			return this._bllUserInfo;
		}
		set
		{
			this._bllUserInfo = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.F_UserID = base.user.UserID;
		this.m_installDir = this.config["InstallDir"].ToString();
		this.m_ShopDir = this.m_installDir + "Shop/";
		if (!base.IsPostBack)
		{
			if (base.Request.QueryString["tag"] != null)
			{
				string text = base.Request.QueryString["tag"].ToLower().Trim();
				Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite(this.conn);
				string text2 = text;
				if (text2 != null)
				{
					if (!(text2 == "addprofav"))
					{
						if (!(text2 == "addshopfav"))
						{
							if (!(text2 == "updateprofav"))
							{
								if (text2 == "updateshopfav")
								{
									this.Pane2.Visible = true;
									this.Panel.Visible = false;
									this.ShopID = int.Parse(base.Request.QueryString["ShopID"]);
									this.bandShopInfo(int.Parse(base.Request.QueryString["F_ID"].ToString()));
									this.BandFShopClass();
									this.DropF_ShopClassID.SelectedValue = base.Request.QueryString["SValue"];
									this.ShopButtonClick.Text = "修改";
									this.m_flag = "1";
								}
							}
							else
							{
								this.Panel.Visible = true;
								this.Pane2.Visible = false;
								this.F_ID = Convert.ToInt32(base.Request.QueryString["f_id"]);
								this.BandFProductClass();
								this.bandUpdateProductInfo(this.F_ID);
								this.m_flag = "0";
								this.ProductButton.Text = "修改";
							}
						}
						else
						{
							this.Panel.Visible = false;
							this.Pane2.Visible = true;
							if (base.Request.QueryString["ShopID"] != null && base.Request.QueryString["ShopID"] != "")
							{
								int num = this.conn.ExecuteCount("select count(*)  from [HLShop_MyFavourite] where F_Type=1 and F_ShopID= " + base.Request.QueryString["ShopID"] + "  and F_userid=" + base.user.UserID.ToString());
								if (num > 0)
								{
									this.ShopButtonClick.Visible = false;
									this.Button1.Visible = false;
									this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('此店铺已经存在。');</script>");
									return;
								}
							}
							this.ShopID = int.Parse(base.Request.QueryString["ShopID"]);
							if (base.user.UserInforRes["ShopID"] != DBNull.Value)
							{
								if (base.user.UserInforRes["ShopID"].ToString() == this.ShopID.ToString())
								{
									this.WriteErrMsg2("", "不能收藏自己的店铺信息！", "../Store/ShopIndex.aspx?ShopID=" + this.ShopID + "&ColumnTag=HomePage");
									return;
								}
							}
							this.BandFShopClass();
							this.bandAddShopInfo(this.ShopID);
							this.m_flag = "1";
						}
					}
					else
					{
						this.Panel.Visible = true;
						this.Pane2.Visible = false;
						this.ProductID = int.Parse(base.Request.QueryString["ProductID"]);
						this.BandFProductClass();
						this.bandAddProductInfo(this.ProductID);
						this.m_flag = "0";
					}
				}
				this.H_FavID.Value = this.F_ID.ToString();
				this.H_ProductID.Value = this.ProductID.ToString();
				this.H_ShopID.Value = this.ShopID.ToString();
			}
			else
			{
				this.Panel.Visible = (this.Pane2.Visible = false);
				this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('输入非法参数，请返回！');location.href='Shop_MyFavourite.aspx'</script>", false);
			}
		}
	}
	protected void bandAddProductInfo(int ProductID)
	{
		string str = "0";
		Shop_Product shop_Product = new Shop_Product(this.conn);
		DataTable productByProductID = shop_Product.GetProductByProductID(ProductID);
		DataRow dataRow = productByProductID.Rows[0];
		if (dataRow != null)
		{
			string str2 = dataRow["ShopID"].ToString();
			this.UserID = int.Parse(dataRow["SalerID"].ToString());
			ProductID = int.Parse(dataRow["ProductID"].ToString());
			this.ProductImage1.Attributes.Add("onload", "ResizeImage(this,50,50)");
			this.ProductImage1.ImageUrl = "../" + dataRow["ProductSmallImageUrl"].ToString();
			string text = dataRow["ProductSmallImageUrl"].ToString();
			this.Hl_ProductName.Text = dataRow["ProductName"].ToString();
			this.Hl_ProductName.NavigateUrl = "../ShowProduct.aspx?ProductID=" + ProductID.ToString();
			string text2 = dataRow["ProductType"].ToString();
			if (text2 != null)
			{
				if (!(text2 == "1"))
				{
					if (!(text2 == "2"))
					{
						if (text2 == "3")
						{
							int num = int.Parse(dataRow["TeamNum"].ToString());
							str = dataRow["TeamPrice" + num].ToString();
						}
					}
					else
					{
						str = dataRow["CurrentPrice"].ToString();
					}
				}
				else
				{
					str = dataRow["StandPrice"].ToString();
				}
			}
			this.LabProductPrice.Text = str + "元";
			this.HL_UserName1.Text = dataRow["SalerName"].ToString();
			this.HL_UserName1.NavigateUrl = "../Store/ShopIndex.aspx?ShopID=" + str2 + "&ColumnTag=ShopInfo";
			this.HL_ProductID.NavigateUrl = "../ShowProduct.aspx?ProductID=" + ProductID.ToString();
			this.LabLeftTime.Text = dataRow["EndDate"].ToString();
			string sql = "select F_Remark from HLShop_MyFavourite where F_ProductID=" + ProductID;
			DataTable dataTable = this.conn.GetDataTable(sql);
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				if (dataTable.Rows[i]["F_Remark"] != DBNull.Value)
				{
					this.TxtF_Remark.Text = dataTable.Rows[i]["F_Remark"].ToString();
				}
			}
		}
	}
	protected void bandUpdateProductInfo(int F_ID)
	{
		Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite(this.conn);
		DataRow favProByF_ID = shop_MyFavourite.GetFavProByF_ID(F_ID);
		if (favProByF_ID != null)
		{
			string str = favProByF_ID["ShopID"].ToString();
			this.UserID = int.Parse(favProByF_ID["SalerID"].ToString());
			this.ProductID = int.Parse(favProByF_ID["ProductID"].ToString());
			this.ProductImage1.ImageUrl = "../" + favProByF_ID["ProductSmallImageUrl"].ToString();
			this.Hl_ProductName.Text = favProByF_ID["ProductName"].ToString();
			this.Hl_ProductName.NavigateUrl = "../ShowProduct.aspx?ProductID=" + this.ProductID.ToString();
			this.LabProductPrice.Text = favProByF_ID["ProductPrice"].ToString() + "元";
			this.HL_UserName1.Text = favProByF_ID["UserName"].ToString();
			this.HL_UserName1.NavigateUrl = "../Store/ShopIndex.aspx?ShopID=" + str + "&ColumnTag=ShopInfo";
			this.HL_ProductID.NavigateUrl = "../ShowProduct.aspx?ProductID=" + this.ProductID.ToString();
			this.LabLeftTime.Text = favProByF_ID["EndDate"].ToString();
			string text = favProByF_ID["F_ProductClassID"].ToString();
			this.DropF_ProductClassID.SelectedValue = favProByF_ID["F_ProductClassID"].ToString();
			this.TxtF_Remark.Text = favProByF_ID["F_Remark"].ToString();
		}
	}
	private void bandShopInfo(int F_ID)
	{
		Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite(this.conn);
		DataRow favShopByF_ID = shop_MyFavourite.GetFavShopByF_ID(F_ID);
		if (favShopByF_ID != null)
		{
			this.UserID = int.Parse(favShopByF_ID["UserID"].ToString());
			this.ShopID = int.Parse(favShopByF_ID["ShopID"].ToString());
			DataSet dataSet = this.conn.GetDataSet("select * from HLShop_Class as a,HLShop_Shop as b where b.ShopCategoryID=a.ClassID and b.ShopID=" + this.ShopID);
			string str = favShopByF_ID["ShopID"].ToString();
			this.HL_ShopName.Text = favShopByF_ID["ShopName"].ToString();
			this.HL_ShopName.NavigateUrl = "../Store/ShopIndex.aspx?ShopID=" + str;
			this.HL_ShopClassName.Text = dataSet.Tables[0].Rows[0]["ClassName"].ToString();
			this.HL_UserName2.Text = favShopByF_ID["UserName"].ToString();
			this.HL_UserName2.NavigateUrl = "../Store/ShopIndex.aspx?ShopID=" + str + "&ColumnTag=ShopInfo";
			this.HL_ShopLel.NavigateUrl = "../Store/ShopIndex.aspx?ShopID=" + str + "&ColumnTag=CreditStatus";
			int userInfoSaleCredietByShopID = this.BllUserInfo.GetUserInfoSaleCredietByShopID(this.ShopID);
			this.HL_ShopLel.Text = "卖家信用：<script type=\"text/javascript\">displayStar(" + userInfoSaleCredietByShopID + ")</script>";
			this.ShopImage1.Attributes.Add("onload", "ResizeImage(this,100,100)");
			if (favShopByF_ID["ShopImageUrl"] != null && favShopByF_ID["ShopImageUrl"].ToString() != "")
			{
				this.ShopImage1.ImageUrl = favShopByF_ID["ShopImageUrl"].ToString();
			}
			else
			{
				this.ShopImage1.ImageUrl = "../Shop/Images/nopicture.gif";
			}
			this.DropF_ShopClassID.SelectedValue = favShopByF_ID["F_ShopClassID"].ToString();
			this.TxtF_Remark1.Text = favShopByF_ID["F_Remark"].ToString();
		}
	}
	private void bandAddShopInfo(int ShopID)
	{
		Shop_Shop shop_Shop = new Shop_Shop(this.conn);
		DataTable shopByShopID = shop_Shop.GetShopByShopID(ShopID);
		if (shopByShopID.Rows.Count == 1)
		{
			DataRow dataRow = shopByShopID.Rows[0];
			if (dataRow != null)
			{
				this.UserID = int.Parse(dataRow["ShopOwnerID"].ToString());
				ShopID = int.Parse(dataRow["ShopID"].ToString());
				DataSet dataSet = this.conn.GetDataSet("select * from HLShop_Class as a,HLShop_Shop as b where b.ShopCategoryID=a.ClassID and b.ShopID=" + ShopID);
				this.HL_ShopName.Text = dataRow["ShopName"].ToString();
				this.HL_ShopName.NavigateUrl = "../Store/ShopIndex.aspx?ShopID=" + dataRow["ShopID"].ToString();
				this.HL_ShopClassName.Text = dataSet.Tables[0].Rows[0]["ClassName"].ToString();
				this.HL_UserName2.Text = dataRow["ShopOwnerName"].ToString();
				int userInfoSaleCredietByShopID = this.BllUserInfo.GetUserInfoSaleCredietByShopID(ShopID);
				this.HL_ShopLel.Text = "卖家信用：<script type=\"text/javascript\">displayStar(" + userInfoSaleCredietByShopID + ")</script>";
				this.ShopImage1.Attributes.Add("onload", "ResizeImage(this,100,100)");
				if (dataRow["ShopImageUrl"] != null && dataRow["ShopImageUrl"].ToString() != "")
				{
					this.ShopImage1.ImageUrl = dataRow["ShopImageUrl"].ToString();
				}
				else
				{
					this.ShopImage1.ImageUrl = "../Shop/Images/nopicture.gif";
				}
			}
		}
	}
	protected void BandFProductClass()
	{
		Shop_FProductClass shop_FProductClass = new Shop_FProductClass(this.conn);
		DataTable fProductClassByUserID = shop_FProductClass.GetFProductClassByUserID(this.F_UserID);
		if (fProductClassByUserID.Rows.Count > 0)
		{
			this.DropF_ProductClassID.DataSource = fProductClassByUserID;
			this.DropF_ProductClassID.DataTextField = "F_ProductClassName";
			this.DropF_ProductClassID.DataValueField = "F_ProductClassID";
			this.DropF_ProductClassID.DataBind();
		}
	}
	protected void BandFShopClass()
	{
		Shop_FShopClass shop_FShopClass = new Shop_FShopClass(this.conn);
		DataTable fShopClassByUserID = shop_FShopClass.GetFShopClassByUserID(this.F_UserID);
		if (fShopClassByUserID.Rows.Count > 0)
		{
			this.DropF_ShopClassID.DataSource = fShopClassByUserID;
			this.DropF_ShopClassID.DataTextField = "F_ShopClassName";
			this.DropF_ShopClassID.DataValueField = "F_ShopClassID";
			this.DropF_ShopClassID.DataBind();
		}
	}
	protected void Button3_Click1(object sender, EventArgs e)
	{
		this.Page.Response.Redirect("Shop_ManageFShopClass.aspx");
	}
	protected void ShopButtonClick_ServerClick(object sender, EventArgs e)
	{
		if (base.Request.QueryString["F_ID"] != null && base.Request.QueryString["F_ID"] != "")
		{
			this.F_ID = int.Parse(base.Request.QueryString["F_ID"]);
		}
		if (base.Request.QueryString["ShopID"] != null && base.Request.QueryString["ShopID"] != "")
		{
			this.ShopID = int.Parse(base.Request.QueryString["ShopID"]);
		}
		Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite(this.conn);
		if (base.Request.QueryString["tag"].ToLower() == "updateshopfav")
		{
			shop_MyFavourite.UpdateFva(-1, this.ShopID, DateTime.Now, 1, "", "", -1, int.Parse(this.DropF_ShopClassID.SelectedValue), this.TxtF_Remark1.Text, this.F_ID);
		}
		else
		{
			if (base.Request.QueryString["tag"].ToLower() == "addshopfav")
			{
				this.F_ID = shop_MyFavourite.InsertFav(new int?(this.F_UserID), new int?(-1), new int?(this.ShopID), new DateTime?(DateTime.Now), new int?(1), "", "", new int?(-1), new int?(int.Parse(this.DropF_ShopClassID.SelectedValue)), this.TxtF_Remark1.Text);
				if (this.F_ID <= 0)
				{
					this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('你已经添加过该店铺！');window.location.href='Shop_MyFavourite.aspx';</script>", false);
				}
			}
		}
		base.Response.Redirect("Shop_MyFavourite.aspx?tag=1&SValue=" + this.DropF_ShopClassID.SelectedValue);
	}
	protected void ProductButton_ServerClick(object sender, EventArgs e)
	{
		this.F_ID = int.Parse(this.H_FavID.Value);
		this.ProductID = int.Parse(this.H_ProductID.Value);
		Shop_MyFavourite shop_MyFavourite = new Shop_MyFavourite(this.conn);
		if (base.Request.QueryString["tag"].ToLower() == "updateprofav")
		{
			shop_MyFavourite.UpdateFva(this.ProductID, -1, DateTime.Now, 0, "", "", int.Parse(this.DropF_ProductClassID.SelectedValue), -1, this.TxtF_Remark.Text, this.F_ID);
		}
		else
		{
			if (base.Request.QueryString["tag"].ToLower() == "addprofav")
			{
				this.F_ID = shop_MyFavourite.InsertFav(new int?(this.F_UserID), new int?(this.ProductID), new int?(-1), new DateTime?(DateTime.Now), new int?(0), "", "", new int?(int.Parse(this.DropF_ProductClassID.SelectedValue)), new int?(-1), this.TxtF_Remark.Text);
				if (this.F_ID <= 0)
				{
					this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('你已经添加过该商品！');window.location.href='Shop_MyFavourite.aspx';</script>");
				}
				else
				{
					this.conn.Execute("Update HLShop_Product set FavouriteNum=FavouriteNum+1 where ProductID=" + this.ProductID);
				}
			}
		}
		base.Response.Redirect("Shop_MyFavourite.aspx?tag=0");
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		this.Page.Response.Redirect("Shop_MyFavourite.aspx?tag=1");
	}
	protected void Button3_Click2(object sender, EventArgs e)
	{
		this.Page.Response.Redirect("Shop_ManageFProductClass.aspx");
	}
	protected void Button3_Click(object sender, EventArgs e)
	{
		this.Page.Response.Redirect("Shop_ManageFShopClass.aspx");
	}
}
